# Maintainer: Ray Donnelly <mingw.android@gmail.com>

_realname=rhash
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.4.2
pkgrel=1
pkgdesc="Great utility for computing hash sums (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url='https://sourceforge.net/projects/rhash/'
depends=("${MINGW_PACKAGE_PREFIX}-gettext")
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cc")
license=('custom' 'BSD')
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/rhash/RHash/archive/v${pkgver}.tar.gz"
        "${_realname}-${pkgver}.tar.gz.asc"::"https://github.com/rhash/RHash/releases/download/v${pkgver}/v${pkgver}.tar.gz.asc"
        "fix-clang-detection.patch::https://github.com/rhash/RHash/commit/4dc5060.patch"
        rhash-link-implib.patch
        rhash-all-mingw.patch)
sha256sums=('600d00f5f91ef04194d50903d3c79412099328c42f28ff43a0bdb777b00bec62'
            'SKIP'
            '0bf197e5884ddf183f12743db81a1311a37d3e8cbd2525feb7e3231870389eed'
            'a9d2491942fd4dc34eafea677d734902761c4e366b997a8e7f7ff6f7b435c9b0'
            'c999da390c4c19ff6c39dd7a1a85b8f07300b9bb72b1507a6255c341b8c2fc4a')
validpgpkeys=('2875F6B1C2D27A4F0C8AF60B2A714497E37363AE')

prepare() {
  cd "${srcdir}"/RHash-${pkgver}
  patch -Np1 -i ../fix-clang-detection.patch
  patch -Np1 -i ../rhash-link-implib.patch
  patch -Np1 -i ../rhash-all-mingw.patch
}

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  cp -R "${srcdir}"/RHash-${pkgver} "${srcdir}"/build-${CARCH}
  cd "${srcdir}"/build-${CARCH}
  ./configure \
     --prefix=${MINGW_PREFIX} \
     --enable-lib-static \
     --enable-lib-shared
  make
}

check() {
  cd "${srcdir}"/build-${CARCH}
  make test test-shared test-static || true
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make -j1 install DESTDIR="${pkgdir}"
  make -j1 install install-gmo DESTDIR="${pkgdir}"

  # license
  # fully qualify path for this because there might be switch in
  # build systems.
  install -Dm644 ${srcdir}/RHash-${pkgver}/COPYING \
    "${pkgdir}${MINGW_PREFIX}"/share/licenses/rhash/LICENSE
}
